from flask import logging
from redis import StrictRedis
import logging

class Config:
    DEBUG = True
    
    """SQL配置"""
    SQLALCHEMY_DATABASE_URI = "mysql://root:@127.0.0.1:3306/information"
    # SQLALCHEMY_DATABASE_URI = "mysql://root:@127.0.0.1:3306/information"
    # 为数据库添加配置
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 在请求结束时候，如果指定此配置为 True ，那么 SQLAlchemy 会自动执行一次 db.session.commit()操作
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    
    """redis配置"""
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    """session设置"""
    SECRET_KEY = "hadhaihfbehqbwque"
    
    SESSION_TYPE = 'redis'
    
    SESSION_USER_SIGNER = True
    
    SESSION_REDIS = StrictRedis(REDIS_HOST, REDIS_PORT)
    
    # 过期时间永久性
    SESSION_PERMANENT = False
    
    PERMANENT_SESSION_LIFETIME = 60 * 60 * 24

    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    DEBUG = True


class ProductionConfig(Config):
    DEBUG = False
    
    LOG_LEVEL = logging.WARNING
    # 生产环境下的数据地址


class TestingConfig(Config):
    DEBUG = True
    # 单元测试
    TESTING = True


config = {
    "development": DevelopmentConfig,
    "test": TestingConfig,
    "product": ProductionConfig
}
